<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .switch {
            height: 100px;
            width: 200px;
            border-radius: 50px;
            /* position: relative; */
            background-color: red;
            transition: background-color 1000ms ease;
        }
        .ball {
            /* UI: 4*n */
            height: 92px;
            width: 92px;
            border-radius: 46px;
            /* position: absolute;
            top: 4px;
            left: 4px; */
            background-color: white;
            transition: transform 1000ms ease, width 1000ms ease;
            /* 
                translate 移动 
                rotate 旋转
                scale 缩放
                skew 倾斜
             */
             /* 重绘 */
             transform: translate(4px, 4px);
        }

        .switch.on {
            background-color: green;
        }
        
        .ball.on {
            transform: translate(104px, 4px);
            /* left: 104px; */
        }
        
    </style>
</head>
<body>
    <div class="switch off">
        <div class="ball off"></div>
    </div>

    <script src="./jq.js"></script>
    <script>
        // 拿clickable变量控制是否可以点击
        // 节流阀
        let clickable = true;
        $('.switch').on('click', function () {
            if (clickable) {
                $('.ball').toggleClass('on');
                $('.switch').toggleClass('on');
                clickable = false;
                setTimeout(function () {
                    clickable = true;
                }, 1000);
            }
        });
    </script>
</body>
</html>